import React, { lazy } from "react";
import { createBrowserRouter, Navigate, useRoutes } from "react-router-dom";
// createHashRouter  createBrowserRouter
const rootRouter = [
  {
    path: "/home",
    Component: lazy(() => import("@/componetns/Home")),
    children: [
      {
        path: "test",
        Component: lazy(() => import("./componetns/Children")),
      },
      {
        path: "about/:id",
        Component: lazy(() => import("@/componetns/About")),
      },
    ],
  },
  {
    path: "/page1",
    Component: lazy(() => import("@/componetns/Page1")),
  },
  {
    path: "/",
    element: <Navigate to='/home' />,
  },
  {
    path: "*",
    element: <Navigate to='/home' />,
  },
];
// setTimeout(() => {
//   rootRouter.push({
//     path: "/page2",
//     Component: lazy(() => import("@/componetns/Page2")),
//   });
// }, 3000);

const Router = () => {
  const routes = useRoutes(rootRouter);
  return routes;
};

export default Router;
